package com.ruoyi.salesman.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.salesman.domain.Salesman;
import com.ruoyi.salesman.service.ISalesmanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务员数据Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/system/salesman")
public class SalesmanController extends BaseController
{
    @Autowired
    private ISalesmanService salesmanService;

    /**
     * 查询业务员数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:list')")
    @GetMapping("/list")
    public TableDataInfo list(Salesman salesman)
    {
        startPage();
        List<Salesman> list = salesmanService.selectSalesmanList(salesman);
        return getDataTable(list);
    }

    /**
     * 导出业务员数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:export')")
    @Log(title = "业务员数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Salesman salesman)
    {
        List<Salesman> list = salesmanService.selectSalesmanList(salesman);
        ExcelUtil<Salesman> util = new ExcelUtil<Salesman>(Salesman.class);
        util.exportExcel(response, list, "业务员数据数据");
    }

    /**
     * 获取业务员数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salesmanService.selectSalesmanById(id));
    }

    /**
     * 新增业务员数据
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:add')")
    @Log(title = "业务员数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Salesman salesman)
    {
        return toAjax(salesmanService.insertSalesman(salesman));
    }

    /**
     * 修改业务员数据
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:edit')")
    @Log(title = "业务员数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Salesman salesman)
    {
        return toAjax(salesmanService.updateSalesman(salesman));
    }

    /**
     * 删除业务员数据
     */
    @PreAuthorize("@ss.hasPermi('system:salesman:remove')")
    @Log(title = "业务员数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salesmanService.deleteSalesmanByIds(ids));
    }
}
